<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="贡献指南" tabindex="-1"><a class="header-anchor" href="#贡献指南"><span>贡献指南</span></a></h2>
<ul>
<li><a href="#bug-reports">Bug 报告</a></li>
<li><a href="#support-questions">帮助支持</a></li>
<li><a href="#core-development-discussion">核心发展讨论</a></li>
<li><a href="#which-branch">选择哪个分支？</a></li>
<li><a href="#compiled-assets">编译资源</a></li>
<li><a href="#security-vulnerabilities">安全漏洞</a></li>
<li><a href="#coding-style">代码风格</a>
<ul>
<li><a href="#phpdoc">PHPDoc</a></li>
<li><a href="#styleci">StyleCI</a></li>
</ul>
</li>
<li><a href="#code-of-conduct">行为准则</a></li>
</ul>
<h2 id="bug-报告" tabindex="-1"><a class="header-anchor" href="#bug-报告"><span>Bug 报告</span></a></h2>
<p>为了鼓励活跃的协作，Laravel 强烈推荐拉取请求，而不仅仅是错误报告。只有标记为「准备好审查」（而不是「草稿」状态）且新功能的所有测试都通过的拉取请求才会进行审核。长时间处于「草稿」状态的非活跃拉取请求将在几天后被关闭。</p>
<p>不过，如果你提交了错误报告，你的问题应包含标题和清晰的问题描述。你还应尽可能提供相关信息和演示问题的代码示例。错误报告的目的是使自己和其他人能够轻松地复制错误并开发修复程序。</p>
<p>请记住，错误报告的创建是希望其他拥有相同问题的人能够与你协作解决问题。不要期望错误报告会自动获得任何活动，或者其他人会迅速修复它。创建错误报告有助于你自己和其他人开始解决问题的路径。如果你想参与，可以通过修复 <a href="https://github.com/issues?q=is%3Aopen+is%3Aissue+label%3Abug+user%3Alaravel" target="_blank" rel="noopener noreferrer">我们的问题跟踪器中列出的任何错误</a> 来帮忙。你必须使用 GitHub 进行身份验证才能查看 Laravel 的所有问题。</p>
<p>如果您在使用 Laravel 时注意到不适当的 DocBlock、PHPStan 或 IDE 警告，请不要创建 GitHub issue。相反，请提交pr来解决问题。</p>
<p>Laravel的源代码在GitHub上进行管理，每个Laravel项目都有各自的仓库：</p>
<h2 id="帮助支持" tabindex="-1"><a class="header-anchor" href="#帮助支持"><span>帮助支持</span></a></h2>
<p>Laravel 的 GitHub 问题跟踪器不适用于提供 Laravel 帮助或支持。请使用以下渠道之一：</p>
<h2 id="核心发展讨论" tabindex="-1"><a class="header-anchor" href="#核心发展讨论"><span>核心发展讨论</span></a></h2>
<p>你可以在 Laravel 框架存储库的 <a href="https://github.com/laravel/framework/discussions" target="_blank" rel="noopener noreferrer">GitHub讨论板</a>中提出新功能或改进现有 Laravel 行为。如果提出了新功能，请愿意实现至少一些完成该功能所需的代码。</p>
<p>关于错误、新功能和现有功能的实现的非正式讨论在 <a href="https://discord.gg/laravel" target="_blank" rel="noopener noreferrer">Laravel Discord server</a> 的 #internals 频道进行。Laravel 的维护者 Taylor Otwell 通常在周一至周五上午 8 点至下午 5 点（UTC-06:00 或美国 / 芝加哥）在频道中出现，并在其他时间不定期出现。</p>
<h2 id="选择哪个分支" tabindex="-1"><a class="header-anchor" href="#选择哪个分支"><span>选择哪个分支?</span></a></h2>
<p><strong>所有</strong> bug 修复都应该发送到支持 bug 修复的最新版本（当前为 <code v-pre>11.x</code>）。Bug 修复<strong>永远不应该</strong>发送到主分支，除非它们修复了仅在即将发布的版本中存在的功能。</p>
<p><strong>次要</strong>功能，如果与当前版本<strong>完全向后兼容</strong>，可以发送到最新的稳定分支（当前为 <code v-pre>11.x</code>）。</p>
<p><strong>重要</strong>新功能或具有破坏性变更的功能应始终发送到主分支，其中包含即将发布的版本。</p>
<h2 id="编译资源" tabindex="-1"><a class="header-anchor" href="#编译资源"><span>编译资源</span></a></h2>
<p>如果你提交的更改会影响编译后的文件，例如 <code v-pre>laravel/laravel</code> 仓库中的 <code v-pre>resources/css</code> 或 <code v-pre>resources/js</code> 中的大多数文件，请不要提交编译后的文件。由于它们的大小很大，维护者无法实际审查它们。这可能被用作将恶意代码注入 Laravel 的方式。为了防御性地防止这种情况，所有编译后的文件都将由 Laravel 维护者生成并提交。</p>
<h2 id="安全漏洞" tabindex="-1"><a class="header-anchor" href="#安全漏洞"><span>安全漏洞</span></a></h2>
<p>如果你发现 Laravel 中存在安全漏洞，请通过电子邮件发送给 Taylor Otwell（<a href="mailto:taylor@laravel.com" target="_blank" rel="noopener noreferrer">taylor@laravel.com</a>）。所有安全漏洞将得到及时处理。</p>
<h2 id="代码风格" tabindex="-1"><a class="header-anchor" href="#代码风格"><span>代码风格</span></a></h2>
<p>Laravel 遵循 <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md" target="_blank" rel="noopener noreferrer">PSR-2</a> 编码标准和 <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md" target="_blank" rel="noopener noreferrer">PSR-4</a> 自动加载标准。</p>
<h3 id="phpdoc" tabindex="-1"><a class="header-anchor" href="#phpdoc"><span>PHPDoc</span></a></h3>
<p>以下是一个有效的 Laravel 文档块示例。请注意，<code v-pre>@param</code> 属性后面跟着两个空格，参数类型，再跟着两个空格，最后是变量名：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 容器注册与绑定</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span><span class="token punctuation">|</span><span class="token keyword">array</span></span>  <span class="token parameter">$abstract</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Closure<span class="token punctuation">|</span><span class="token keyword">string</span><span class="token punctuation">|</span><span class="token keyword">null</span></span>  <span class="token parameter">$concrete</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">bool</span></span>  <span class="token parameter">$shared</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@throws</span> <span class="token class-name"><span class="token punctuation">\</span>Exception</span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">bind</span><span class="token punctuation">(</span><span class="token variable">$abstract</span><span class="token punctuation">,</span> <span class="token variable">$concrete</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">,</span> <span class="token variable">$shared</span> <span class="token operator">=</span> <span class="token constant boolean">false</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>当 <code v-pre>@param</code> 或 <code v-pre>@return</code> 属性由于使用原生类型而出现冗余时，可以将其移除：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 执行任务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">handle</span><span class="token punctuation">(</span><span class="token class-name type-declaration">AudioProcessor</span> <span class="token variable">$processor</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">//</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>但是，当原生类型是泛型时，请通过使用 <code v-pre>@param</code> 或 <code v-pre>@return</code> 属性指定泛型类型：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 获取消息</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">array</span></span>&lt;int, \Illuminate\Mail\Mailables\Attachment></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">attachments</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">array</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token class-name static-context">Attachment</span><span class="token operator">::</span><span class="token function">fromStorage</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/path/to/file'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="styleci" tabindex="-1"><a class="header-anchor" href="#styleci"><span>StyleCI</span></a></h3>
<p>别担心你的代码风格，<a href="https://styleci.io/" target="_blank" rel="noopener noreferrer">StyleCI</a> 是一个自动化的代码风格工具，它会在拉取请求合并后自动将任何风格修复合并到 Laravel 仓库中。这使我们能够专注于贡献的内容而不是代码风格上。</p>
<h2 id="行为准则" tabindex="-1"><a class="header-anchor" href="#行为准则"><span>行为准则</span></a></h2>
<p>Laravel 的行为准则源自于 Ruby 的行为准则。如果违反了行为准则，可以向 Taylor Otwell（taylor@laravel.com）报告：</p>
<ul>
<li>参与者应尊重不同的观点。</li>
<li>参与者必须确保他们的语言和行为没有人身攻击和贬低个人言论。</li>
<li>在解释他人的言行时，参与者应始终保持良好的意图。</li>
<li>不能容忍可合理视为骚扰的行为。</li>
</ul>
<blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/contributionsmd/16646" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/co...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/contributionsmd/16646" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/co...</a></p>
</blockquote>
</div></template>


